package com.sz.bean;

import com.sz.util.Tool;
import org.dom4j.Element;

import java.util.List;

/**
 * @author 石震
 *
 */
public class SysiniConfig {
	
	private static Sysini sysini;
	
	private SysiniConfig(){
		
	}
	
	public static Sysini getSysini(){
		
		if(sysini == null){
            synchronized(SysiniConfig.class){
                if(sysini == null){
                    initSysini();
                }
            }
		}
		
		return sysini;
	}
	
	private static Sysini initSysini(){
		
		sysini = new Sysini();
		readConfig(sysini);
		
		return sysini;
	}
	
	@SuppressWarnings("unchecked")
    private static void readConfig(Sysini sysini){
		/* 获取本文件实际路径 */
		String dirPath = SysiniConfig.class.getResource("/").getPath();
		// 获取xml文件的内容
		Element root = Tool.getRootElement("sysini.xml", dirPath);
		if(root == null){
			System.out.println("请先上传文件");
			return;
		}
		// 获取第一个element
		List<Element> elementList = root.elements();
		// 遍历第一个element
		for(Element ge : elementList){
			String appName = ge.attributeValue("appName");
			String title = ge.attributeValue("title");
			String webTitle = ge.attributeValue("webTitle");
			String keywords = ge.attributeValue("keywords");
			String description = ge.attributeValue("description");
			String copyright = ge.attributeValue("copyright");
			String address = ge.attributeValue("address");
			String tel = ge.attributeValue("tel");
			String url = ge.attributeValue("url");
			String systemClose = ge.attributeValue("systemStatus");
			String privateKey = ge.attributeValue("privateKey");
			String domain = ge.attributeValue("domain");
			String default_password = ge.attributeValue("default_password");
			String smsUrl = ge.attributeValue("smsUrl");
			String smsAppkey = ge.attributeValue("smsAppkey");
			String smsSecret = ge.attributeValue("smsSecret");
			String smsFreeSignName = ge.attributeValue("smsFreeSignName");
			String smsTemplateCode = ge.attributeValue("smsTemplateCode");
			String smsTemplateOverdue = ge.attributeValue("smsTemplateOverdue");
			
			sysini.setAppName(appName);
			sysini.setTitle(title);
			sysini.setWebTitle(webTitle);
			sysini.setKeywords(keywords);
			sysini.setDescription(description);
			sysini.setCopyright(copyright);
			sysini.setAddress(address);
			sysini.setTel(tel);
			sysini.setDefault_password(default_password);
			sysini.setUrl(url);
		}
		
	}
	
}
